import sys

import ezdxf


def is_in_gbk_charset(char):
    try:
        char.encode('GBK')
        return True
    except UnicodeEncodeError:
        return False


# 输出所有图层名称
def print_all_layers(filename):
    doc = ezdxf.readfile(filename)
    for layer in doc.layers:
        name = layer.dxf.name
        first_char = name[0]

        if is_in_gbk_charset(first_char):
            print(name)


if __name__ == '__main__':
    dxf_path = sys.argv[1]  # "data/成果数据.dxf"

    # 打印dwg数据所有图层
    print_all_layers(dxf_path)
